package zli.proxy.dynamicproxy.jdkproxy;

import sun.misc.ProxyGenerator;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * @Desc
 * @Author Zerlinda
 * @Date 2022/5/13 14:31
 * @Version 1.0
 */
public class Test {
    public static void main(String[] args) {
        JdkMeiPo meiPo = new JdkMeiPo();
        IPerson zhangsan = meiPo.getInstance(new ZhangSan());
        zhangsan.findLove();
        zhangsan.buyInsure();

        byte [] bytes = ProxyGenerator.generateProxyClass("$Proxy0", new Class[]{IPerson.class});
        try {
            FileOutputStream os = new FileOutputStream("E://$Proxy0.class");
            os.write(bytes);
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        IPerson zhaoLiu = meiPo.getInstance(new ZhaoLiu());
        zhaoLiu.findLove();
        zhaoLiu.buyInsure();
    }
}
